package com.rq.adapter;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.rq.rvlibrary.BaseAdapter;
import com.rq.rvlibrary.BaseViewHolder;
import com.rq.rvlibrary.OnItemClickListener;
import com.rq.rvlibrary.RecyclerUtil;

import java.util.ArrayList;
import java.util.List;

public class KeepAct extends Activity implements OnItemClickListener {
    BaseAdapter mAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_keep);
        mAdapter = new BaseAdapter(this, R.layout.item_keep, KeepViewHolder.class);
        new RecyclerUtil(mAdapter).set2View(((RecyclerView) findViewById(R.id.recycler)));
        List<String> data = new ArrayList<>();
        data.add("1");
        data.add("2");
        data.add("3");
        data.add("4");
        data.add("5");
        data.add("6");
//        data.add("15");
//        data.add("16");
//        data.add("17");
//        data.add("18");
//        data.add("19");
//        data.add("20");
//        data.add("21");
//        data.add("22");
//        data.add("23");
//        data.add("24");
//        data.add("25");
//        data.add("26");
//        data.add("27");
//        data.add("28");
//        data.add("29");
        mAdapter.setData(data);
        mAdapter.addOnItemClickListener(this, R.id.btn_del);
    }

    public void deleteLen(View view) {
        mAdapter.removeItems(Integer.parseInt(((EditText) findViewById(R.id.input1)).getText().toString())
                , Integer.parseInt(((EditText) findViewById(R.id.input2)).getText().toString()));

        main.postDelayed(new Runnable() {
            @Override
            public void run() {
                LOG.e("KeepAct", "79:");
                mAdapter.show();
            }
        }, 1000);
    }

    public void addItem(View view) {
        mAdapter.addData(String.valueOf(mAdapter.getDataSize()));
    }

    public void onResult(View view) {
        LOG.bean("KeepAct", mAdapter.getItemInput());
    }

    Handler main = new Handler(Looper.getMainLooper());

    @Override
    public void onItemClick(final BaseAdapter adapter, BaseViewHolder holder, Object o, View v, int position) {
        adapter.removeItem(position);
        LOG.e("KeepAct", "75:");
        main.postDelayed(new Runnable() {
            @Override
            public void run() {
                LOG.e("KeepAct", "79:");
                adapter.show();
            }
        }, 1000);
    }
}
